package com.mobile.struts.action.grid;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.mobile.business.grid.IGridTableBusiness;
import com.mobile.model.GridTable;
import com.mobile.struts.action.BaseDispatchAction;
import com.mobile.tools.JsonHelp;

public class GridImplAction extends BaseDispatchAction {
	/*private ITestGridTableBusiness businessClass=(ITestGridTableBusiness)getWac()
										.getBean(ITestGridTableBusiness.BEAN_ID);*/
	private IGridTableBusiness getBusinessBean(){
		return (IGridTableBusiness)getWac()
		.getBean(IGridTableBusiness.BEAN_ID);
	}
	
	protected JsonHelp<GridTable> jsonHelp=new JsonHelp<GridTable>();
	
	public ActionForward show(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		request.setAttribute("title","Grid");
		request.setAttribute("jsSrc","GridTable.js");
		String uniqueCode = request.getParameter("uniqueCode");
		if(uniqueCode==null||"".equals(uniqueCode)){
			uniqueCode="10066";
		}
		request.setAttribute("uniqueCode", uniqueCode);
		return mapping.findForward("dynamicGrid");
	}
	
	public ActionForward tableInfo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		String uniqueCode=request.getParameter("uniqueCode");
		//TestGridTableBusiness tgt=new TestGridTableBusiness();
		GridTable gt=getBusinessBean().getGridTable(uniqueCode);

		PrintWriter out=null;
		try {
			out=response.getWriter();
			//StringBuffer content=new StringBuffer();
			JsonHelp<GridTable> jh=new JsonHelp<GridTable>();
/*			content.append("{success: true,");
			content.append("data:"+jh.getJson(gt));
			content.append("}");*/
			out.println(jh.getJsonAjaxSuccess(gt));
		} catch(Exception e){
			e.printStackTrace();
		}finally{		
			out.close();
		}
		return null;
	}
}
